var infoCon = null;
/**
 * 初始化
**/
function tabsheetInit()
{
	var patInfo = $("input[name='patInfo']");
	patInfo.attr("readonly","readonly");
	patInfo.css("background-color","#F0F0F0");
	infoCon = 0;
	var conInnerConWidth = $(".patTabSheet").width();
	var conSize = 5 ;
	var tabHeight = $(".patTabSheet a").height();
	
	$(".patTabSheet a").click(function(){
		var index = $(".patTabSheet a").index(this);
		tabsheetChanged(conInnerConWidth, tabHeight, index);
		return false;
	});
	
}

/**
 * 页面切换
**/
function tabsheetChanged(conInnerConWidth, tabHeight, index)
{
	if(infoCon == index)
	{
		return;
	}
	var tabId = "con" + index ;
//	$("#" + "con" +infoCon).addClass("tabsheet_none");
	$("#" + "con" +infoCon).fadeOut(0);
//	$("#" + tabId).removeClass("tabsheet_none");
	$("#" + tabId).fadeIn(1000);
	$(".patTabSheet").css("background-position","0 -"+index*tabHeight+"px");
	infoCon = index;
}

/**
 * 查询
**/
function showPatInfo()
{
	var mrn = $("#patinfo_search_mrn").val();
	if(mrn == ""|| mrn == undefined || mrn == null)
	{
		messageAlert(2,"请输入病历号！",function()
				{
			this.close();
			choose_close();
		});
	}
	else if(!findPatByMrn(mrn))
	{
		messageAlert(2,"请输入正确的病历号！",function()
				{
			this.close();
			choose_close();
		});
	}
	else
	{
		showPatinfo_basicData();
		showPatinfo_treatDataList(1);
		showPatinfo_funDataList(1);
		showPatinfo_bloodDataList(1);
	}
}

function showPatinfo_basicData(){
	var mrn = $("#patinfo_search_mrn").val();
	var url = projectName + "/pat/getPatInfoByMrn.do?date=" + new Date().getTime();
	$.ajax({
		url: url,
		async: false,
		data: {
			mrn: mrn
		},
		success: function(data,result){
			$("input[name='patInfo']").val("");
			$("#patInfo_addr").attr("title","");
			$("#patInfo_medical_history").attr("title","");
			$("#patInfo_mrn").val(data.mrn);
			$("#patInfo_name").val(data.name);
			$("#patInfo_id_card").val(data.id_card);
			$("#patInfo_sex").val(data.sex);
			$("#patInfo_age").val(data.age);
			$("#patInfo_addr").val(data.addr);
			$("#patInfo_addr").attr("title",data.addr);
			$("#patInfo_phone").val(data.phone);
			$("#patInfo_tumor_site").val(data.tumor_site);
			$("#patInfo_dffrnttn").val(data.dffrnttn);
			$("#patInfo_tnm").val(data.tnm);
			$("#patInfo_pathology").val(data.pathology);
			$("#patInfo_egfr").val(data.egfr);
			$("#patInfo_smoke").val(data.smoke);
			$("#patInfo_medical_history").val(data.medical_history);
			$("#patInfo_medical_history").attr("title",data.medical_history);
			
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			alert(XMLHttpRequest.status);
			alert(XMLHttpRequest.readyState);
			alert(textStatus);
		}
	});
}

function showPatinfo_treatDataList(pageNo)
{
	var mrn = $("#patinfo_search_mrn").val();
	if(pageNo == null || pageNo == "" || pageNo == undefined) 
	{
		pageNo = 1;
	}
	else
	var url = projectName + "/pat/getPatInfoTreatPage.do?date=" + new Date().getTime();
	$.ajax({
		url: url,
		async: false,
		data: {
			mrn: mrn,
			pageNo: pageNo
		},
		success: function(data,result){
			$("#patinfo_treatTable").empty();
			var treatList = data.result;
			$("#patinfo_treatTable").append("<thead><tr><th class='date_time'>治疗日期</th><th>治疗方式</th><th>主治医师</th><th>备注</th></tr></thead>");
			for(var i = 0 ; i < treatList.length; i++)
			{
				$("#patinfo_treatTable").append("<tr><td>" + treatList[i].t_dateString + "</td><td>" + treatList[i].therary+"</td><td>" + treatList[i].d_name + "</td><td title='"+treatList[i].memo+"'>"+treatList[i].memo+"</td></tr>");
//				$("#logMgrTable tr:nth-child(even)").addClass("trevencolor");
			}
			data.result = null;
			var treatPageInfo=JSON.stringify(data);
			getDivPage("patinfoTreat",treatPageInfo,showPatinfo_treatDataList);
		},
		 error: function(XMLHttpRequest, textStatus, errorThrown) {
			 alert(XMLHttpRequest.status);
			 alert(XMLHttpRequest.readyState);
			 alert(textStatus);
		},
	});
}

function showPatinfo_funDataList(pageNo){
	var mrn = $("#patinfo_search_mrn").val();
	if(pageNo == null || pageNo == "" || pageNo == undefined) 
	{
		pageNo = 1;
	}
	else
	var url = projectName + "/pat/getPatInfoFunPage.do?date=" + new Date().getTime();
	$.ajax({
		url: url,
		async: false,
		data: {
			mrn: mrn,
			pageNo: pageNo
		},
		success: function(data,result){
			$("#patinfo_funTable").empty();
			var funList = data.result;
			$("#patinfo_funTable").append("<thead><tr><th class='date_time'>随访日期</th><th>医师姓名</th><th>随访记录</th></tr></thead>");
			for(var i = 0 ; i < funList.length; i++)
			{
				$("#patinfo_funTable").append("<tr><td>" + funList[i].f_dateString + "</td><td>" + funList[i].d_name + "</td><td title='"+funList[i].memo+"'>"+funList[i].memo+"</td></tr>");
//				$("#logMgrTable tr:nth-child(even)").addClass("trevencolor");
			}
			data.result = null;
			var funPageInfo=JSON.stringify(data);
			getDivPage("patinfoFun",funPageInfo,showPatinfo_funDataList);
		},
		 error: function(XMLHttpRequest, textStatus, errorThrown) {
			 alert(XMLHttpRequest.status);
			 alert(XMLHttpRequest.readyState);
			 alert(textStatus);
		},
	});
}

function showPatinfo_bloodDataList(pageNo)
{
	var mrn = $("#patinfo_search_mrn").val();
	if(pageNo == null || pageNo == "" || pageNo == undefined) 
	{
		pageNo = 1;
	}
	else
	var url = projectName + "/pat/getPatInfoBloodPage.do?date=" + new Date().getTime();
	$.ajax({
		url: url,
		async: false,
		data: {
			mrn: mrn,
			pageNo: pageNo
		},
		success: function(data,result){
			$("#patinfo_bloodTable").empty();
			var bloodList = data.result;
			$("#patinfo_bloodTable").append("<thead><tr><th class='date_time'>治疗日期</th><th>提取状态</th><th>种类</th><th>数量</th><th>CYFRAZ1-1</th><th>癌胚抗原</th><th>淋巴细胞活性</th><th>描述</th></tr></thead>");
			for(var i = 0 ; i < bloodList.length; i++)
			{
				$("#patinfo_bloodTable").append("<tr><td>" + bloodList[i].g_dateString + "</td><td>" + bloodList[i].type+"</td><td>" + bloodList[i].g_type + "</td><td>"+bloodList[i].amount+"</td><td>"+bloodList[i].cyfString+"</td><td>"+bloodList[i].ceaString+"</td><td>"+bloodList[i].activeString+"</td><td title='"+bloodList[i].memo+"'>"+bloodList[i].memo+"</td></tr>");
//				$("#logMgrTable tr:nth-child(even)").addClass("trevencolor");
			}
			data.result = null;
			var bloodPageInfo=JSON.stringify(data);
			getDivPage("patinfoBlood",bloodPageInfo,showPatinfo_bloodDataList);
		},
		 error: function(XMLHttpRequest, textStatus, errorThrown) {
			 alert(XMLHttpRequest.status);
			 alert(XMLHttpRequest.readyState);
			 alert(textStatus);
		},
	});
}
